




/*
'===============================================================================
'  MP.LayerHelper.MP_OBS.BL.MbModuleDepartManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using MP.LayerHelper.MP_OBS.BLL;
using MP.LayerHelper.MP_OBS.DAL;
using MP.LayerHelper.MP_OBS.DAL.EntityClasses;
using MP.LayerHelper.MP_OBS.DAL.FactoryClasses;
using MP.LayerHelper.MP_OBS.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MP.LayerHelper.MP_OBS.BLL
{
	public class MbModuleDepartManagerBase : ManagerBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		
		public MbModuleDepartManagerBase()
		{
			// Nothing for now.
		}
		
		public override string TableName()
        {
            return "MbModuleDepart";
        }
		
		public MbModuleDepartEntity Insert(MbModuleDepartEntity _MbModuleDepartEntity)
		{
			return Insert(_MbModuleDepartEntity, "");
		}
		
		public MbModuleDepartEntity Insert(MbModuleDepartEntity _MbModuleDepartEntity, string controlId)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(_MbModuleDepartEntity, true);
				MbModuleDepartFields field = new MbModuleDepartFields();
                LogEntity(_MbModuleDepartEntity, field, AcInsert, controlId);
			}
			return _MbModuleDepartEntity;
		}

		
		public MbModuleDepartEntity Insert(Guid Id, string ModCode, Guid DepartId)
		{
			MbModuleDepartEntity _MbModuleDepartEntity = new MbModuleDepartEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_MbModuleDepartEntity.Id = Id;
				_MbModuleDepartEntity.ModCode = ModCode;
				_MbModuleDepartEntity.DepartId = DepartId;
				MbModuleDepartFields field = new MbModuleDepartFields();
                LogEntity(_MbModuleDepartEntity, field, AcInsert);
				adapter.SaveEntity(_MbModuleDepartEntity, true);
			}
			return _MbModuleDepartEntity;
		}

		public MbModuleDepartEntity Insert(string ModCode, Guid DepartId)
		{
			MbModuleDepartEntity _MbModuleDepartEntity = new MbModuleDepartEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_MbModuleDepartEntity.ModCode = ModCode;
				_MbModuleDepartEntity.DepartId = DepartId;
				adapter.SaveEntity(_MbModuleDepartEntity, true);
				MbModuleDepartFields field = new MbModuleDepartFields();
                LogEntity(_MbModuleDepartEntity, field, AcInsert);
			}
			return _MbModuleDepartEntity;
		}
		
		public bool Update(MbModuleDepartEntity _MbModuleDepartEntity)
        {
            return Update(_MbModuleDepartEntity, "");
        }

		public bool Update(MbModuleDepartEntity _MbModuleDepartEntity, string controlId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(MbModuleDepartFields.Id == _MbModuleDepartEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_MbModuleDepartEntity, filter);
				toReturn = true;
				
				MbModuleDepartFields field = new MbModuleDepartFields();
                LogEntity(_MbModuleDepartEntity, field, AcUpdate, controlId);
			}
			return toReturn;
		}
		
		public bool Update(MbModuleDepartEntity _MbModuleDepartEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_MbModuleDepartEntity, filter);
				toReturn = true;
				
				MbModuleDepartFields field = new MbModuleDepartFields();
                LogEntity(_MbModuleDepartEntity, field, AcUpdate);
			}
			return toReturn;
		}

		public bool Update(Guid Id, string ModCode, Guid DepartId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				MbModuleDepartEntity _MbModuleDepartEntity = new MbModuleDepartEntity(Id);
				if (adapter.FetchEntity(_MbModuleDepartEntity))
				{
				
					_MbModuleDepartEntity.ModCode = ModCode;
					_MbModuleDepartEntity.DepartId = DepartId;
					adapter.SaveEntity(_MbModuleDepartEntity, true);
					toReturn = true;
					
					MbModuleDepartFields field = new MbModuleDepartFields();
					LogEntity(_MbModuleDepartEntity, field, AcUpdate);
				}
			}
			return toReturn;
		}

		public bool Delete(Guid Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				MbModuleDepartEntity _MbModuleDepartEntity = new MbModuleDepartEntity(Id);
				if (adapter.FetchEntity(_MbModuleDepartEntity))
				{
					adapter.DeleteEntity(_MbModuleDepartEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("MbModuleDepartEntity", null);
			}
		}
		
		
		public int DeleteById(Guid Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MbModuleDepartEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByModCode(string ModCode)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.ModCode == ModCode);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MbModuleDepartEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByDepartId(Guid DepartId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MbModuleDepartEntity", filter);
			}
			return toReturn;
		}
		

		
		public MbModuleDepartEntity SelectOne(Guid Id)
		{
			MbModuleDepartEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				MbModuleDepartEntity _MbModuleDepartEntity = new MbModuleDepartEntity(Id);
				if (adapter.FetchEntity(_MbModuleDepartEntity))
				{
					toReturn = _MbModuleDepartEntity;
				}
			}
			return toReturn;
		}

		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbModuleDepartCollection = new EntityCollection(new MbModuleDepartEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbModuleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection<MbModuleDepartEntity>
		public EntityCollection<MbModuleDepartEntity> SelectAllLST()
		{
			EntityCollection<MbModuleDepartEntity> _MbModuleDepartCollection = new EntityCollection<MbModuleDepartEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbModuleDepartCollection, null, 0, null);
			}
			return _MbModuleDepartCollection;
		}
		
		// Return EntityCollection<MbModuleDepartEntity>
		public EntityCollection<MbModuleDepartEntity> SelectAllLST_Paged(int PageNumber, int PageSize)
		{
			EntityCollection<MbModuleDepartEntity> _MbModuleDepartCollection = new EntityCollection<MbModuleDepartEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbModuleDepartCollection, null, 0, null, null, PageNumber, PageSize);
			}
			return _MbModuleDepartCollection;
		}


		
		// Return EntityCollection<MbModuleDepartEntity>
		public EntityCollection<MbModuleDepartEntity> SelectByIdLST(Guid Id)
		{
			EntityCollection<MbModuleDepartEntity> _MbModuleDepartCollection = new EntityCollection<MbModuleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbModuleDepartCollection, filter, 0, null);
			}
			return _MbModuleDepartCollection;
		}
		
		// Return EntityCollection<MbModuleDepartEntity>
		public EntityCollection<MbModuleDepartEntity> SelectByIdLST_Paged(Guid Id, int PageNumber, int PageSize)
		{
			EntityCollection<MbModuleDepartEntity> _MbModuleDepartCollection = new EntityCollection<MbModuleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbModuleDepartCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MbModuleDepartCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(Guid Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbModuleDepartCollection = new EntityCollection(new MbModuleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbModuleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT_Paged(Guid Id, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbModuleDepartCollection = new EntityCollection(new MbModuleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbModuleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MbModuleDepartEntity>
		public EntityCollection<MbModuleDepartEntity> SelectByModCodeLST(string ModCode)
		{
			EntityCollection<MbModuleDepartEntity> _MbModuleDepartCollection = new EntityCollection<MbModuleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.ModCode == ModCode);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbModuleDepartCollection, filter, 0, null);
			}
			return _MbModuleDepartCollection;
		}
		
		// Return EntityCollection<MbModuleDepartEntity>
		public EntityCollection<MbModuleDepartEntity> SelectByModCodeLST_Paged(string ModCode, int PageNumber, int PageSize)
		{
			EntityCollection<MbModuleDepartEntity> _MbModuleDepartCollection = new EntityCollection<MbModuleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.ModCode == ModCode);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbModuleDepartCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MbModuleDepartCollection;
		}
		
		// Return DataTable
		public DataTable SelectByModCodeRDT(string ModCode)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbModuleDepartCollection = new EntityCollection(new MbModuleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.ModCode == ModCode);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbModuleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByModCodeRDT_Paged(string ModCode, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbModuleDepartCollection = new EntityCollection(new MbModuleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.ModCode == ModCode);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbModuleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MbModuleDepartEntity>
		public EntityCollection<MbModuleDepartEntity> SelectByDepartIdLST(Guid DepartId)
		{
			EntityCollection<MbModuleDepartEntity> _MbModuleDepartCollection = new EntityCollection<MbModuleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbModuleDepartCollection, filter, 0, null);
			}
			return _MbModuleDepartCollection;
		}
		
		// Return EntityCollection<MbModuleDepartEntity>
		public EntityCollection<MbModuleDepartEntity> SelectByDepartIdLST_Paged(Guid DepartId, int PageNumber, int PageSize)
		{
			EntityCollection<MbModuleDepartEntity> _MbModuleDepartCollection = new EntityCollection<MbModuleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbModuleDepartCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MbModuleDepartCollection;
		}
		
		// Return DataTable
		public DataTable SelectByDepartIdRDT(Guid DepartId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbModuleDepartCollection = new EntityCollection(new MbModuleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbModuleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByDepartIdRDT_Paged(Guid DepartId, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbModuleDepartCollection = new EntityCollection(new MbModuleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbModuleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbModuleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		

	}
}
